package utils;

import java.util.concurrent.TimeUnit;

public class ExecTime {

	private long start;
	private static final TimeUnit unit = TimeUnit.MILLISECONDS;
	
	public static ExecTime getStarted(){
		return new ExecTime(); 
	}
	
	private ExecTime(){
		this.reset();
	}
	
	public ExecTime reset(){
		start = System.nanoTime();
		return this;
	}
	
	//return time in milisec
	public long getTime(){
		long end = System.nanoTime();
		return unit.convert(end - start, TimeUnit.NANOSECONDS);
	}
	
	public long getTime(TimeUnit un){
		long end = System.nanoTime();
		TimeUnit myunit = un;
		if(un == null){
			myunit = unit;
		}
		return myunit.convert(end - start, TimeUnit.NANOSECONDS);
	}
	
	
}
